const meeting = require("../../database/meeting");
const meet = require("../../database/meet");
const uuid = require("uuid");

module.exports = async (req,res,next) =>{
  const {name, people, meetId, startTime, duration} = req.body;

  let state = 0;

  const p = Array.isArray(people) ? people : JSON.parse(people);

  const mid = "meeting-" + uuid.v1();

  if(startTime <= Date.now()){
    state = 1;
    await meet.updateOne({
      meetId
    }, {
      state: true,
      meetingId: mid
    })
  }

  await meeting.insertMany({
    meetingId: mid,
    name,
    people: p,
    state: state-0,
    count: p.length,
    meetId,
    startTime:startTime-0,
    duration:duration-0
  })

  res.send({
    code:1,
    msg:"会议添加成功"
  })

}